#include <QDebug>

#include "sensor/Camera.h"

#include "QwImageViewer.h"

QwImageViewer::QwImageViewer( const int width, const int height )
{
    image_label = new QLabel( this );
    resize( width, height );
    setWindowTitle( "Camera view" );
}

void QwImageViewer::refresh( const QImage* image )
{
    //m_mutexCamera.lockForRead();

/*
    int width = image->width();
    int height = image->height();

    IplImage* pic_cv = qImage2IplImage( image );
    IplImage* pic_gray = cvCreateImage( cvSize( width, height ), IPL_DEPTH_8U, 1 );
    cvCvtColor( pic_cv, pic_gray, CV_RGB2GRAY );
    IplImage* pic_edge = cvCreateImage( cvSize( width, height ), IPL_DEPTH_8U, 1 );
    cvCanny( pic_gray, pic_edge, 10, 100, 3 );

    QImage image_processed = IplImage2QImage( pic_edge );
*/

    image_label->setPixmap( QPixmap::fromImage( *image) );

    image_label->show();
    image_label->adjustSize();

/*
    cvReleaseImage( &pic_cv );
    cvReleaseImage( &pic_gray );
    cvReleaseImage( &pic_edge );
*/
    //m_mutexCamera.unlock();
}

void QwImageViewer::keyPressEvent( QKeyEvent* event )
{
    emit cmdReceived( event );
}
